home *** CD-ROM | disk | FTP | other *** search
- Path: pubxfer.news.psi.net !usenet
- From: dcomery.dynalog@LNN.COM (David Comery)
- Newsgroups: comp.lang.c++
- Subject: Re: Operator Overloading question
- Date: 23 Jan 1996 20:12:37 GMT
- Organization: Dynalog Technologies
- Message-ID: <4e3ffl$58l@pubxfer2.news.psi.net>
- References: <Robert.Lendvai-2101960120380001@129.170.80.94>
- Reply-To: pspiro.dynalog@LNN.COM
- NNTP-Posting-Host: ftp.dynalog.com
- X-Newsreader: WinVN 0.92.6+
-
- In article <Robert.Lendvai-2101960120380001@129.170.80.94>, Robert.Lendvai@dartmouth.edu (Robert Lendvai) says:
- >
- >Codewarrior is saying this:
- >
- >Error : illegal 'operator' declaration
- >player.h line 23 friend Boolean operator == (Player * member, char *
- >dude); //Check to see if a player has this name
- >
- >about the following code, but I have no idea why. Can anyone help?
- >
- >
- >
- >#include <iostream.h>
- >#include <stdlib.h>
- >
- >class Player{
- >
- >private:
- >
- >
- >char * name;
- >int rating;
- >Player * next;
- >
- >public:
- >
- >Player(char * s);
- >Player();
- >~Player();
- >
- >
- >
- >
- >friend class Player_list;
- >friend Boolean operator == (Player * member, char * dude); //Check to see
- >if a //player has this name
- >
- >};
-
- You can avoid the problem altogether by making the ==operator
- a member function of the class, instead of making it a friend function:
-
- class Player
- {
- public:
- friend class Player_list;
- Boolean operator==( char * dude);
- };
-
- this is the easist way, although the other way will work too.
-
- -Pete Spiro
-